package com.andova.util

import io.reactivex.Observer
import io.reactivex.disposables.Disposable

/**
 * Created by Administrator on 2019-07-09.
 *
 * @author kzaxil
 * @since 1.0.0
 */
abstract class ObserverFunc<T> : Observer<T> {
    private var dis: Disposable? = null
    fun dispose() = dis?.dispose()
    override fun onComplete(): Unit = run { dispose() }
    override fun onNext(t: T) = run { }
    override fun onSubscribe(d: Disposable): Unit = run { dis = d }
    override fun onError(e: Throwable) {}
}

abstract class ObserverFunc1<T> : ObserverFunc<T>() {
    override fun onNext(t: T): Unit = run { next(t) }
    abstract fun next(t: T)
}

abstract class ObserverFunc2<T> : ObserverFunc1<T>() {
    override fun onError(e: Throwable): Unit = run { error(e) }
    abstract fun error(e: Throwable)
}